import { math, SceneAsset, tween, Vec2, view } from "cc";
import * as fgui from "fairygui-cc";
import Instance from "../../../Core/Utils/Instance";
import { LayerManager } from "../../../Core/Layer/LayerManager";
// import { ExternalGLoader } from "../../../Core/Res/ExternalGLoader";
import ModuleWindow from "../window/ModuleWindow";
import TimerMgr from "../../../Core/Timer/TimerMgr";
import UICore from "../../../Core/Res/UICore";
import SpineLoader from "../../../Core/Res/SpineLoader";
import EventMgr from "../../../Core/Event/EventMgr";
import { GameModels } from "../socket/GameModels";
// import { Grids } from "../view/gameEliminate/Grids";
import AudioManager from "../../../Core/Audio/AudioManager";
export class ViewManager {
    private _loading: fgui.GComponent;
    public static get ins(): ViewManager {
        return Instance.get(ViewManager);
    }
    constructor() {
    }
    /**
      * 显示提示信息
      * @param str 提示信息内容，支持字符串和数字类型
      * @returns 无返回值
      */
    public showtips(str: string | number): void {
        const render: fgui.GComponent = fgui.UIPackage.createObject(`Common`, `TipsRender`).asCom;
        render.touchable = false;
        render.getChild("tips").text = str + "";
        const widthH: number = view.getVisibleSize().width;
        const heightH: number = view.getVisibleSize().height;
        render.x = (widthH - render.width) >> 1;
        render.y = ((heightH - render.height) >> 1) - 150;
        LayerManager.ins.tip.addChild(render);
        tween(render).to(1.5, { y: render.y - 100 }).call((data: fgui.GObject) => {
            data.removeFromParent();
            data.dispose();
        }).start();
    }
    public showloading(): void {
        if (!this._loading) {
            this._loading = UICore.createObject(`Common`, `LoadingView`).asCom;
            this._loading.setSize(LayerManager.ins.loading.width, LayerManager.ins.loading.height);
            this._loading.name = `loading`;
        }
        if (LayerManager.ins.loading.getChild(`loading`)) {
            return;
        }
        LayerManager.ins.loading.addChild(this._loading);
        TimerMgr.ins.add(5000, 1, this.removeLoading, this);
    }
    public removeLoading(): void {
        TimerMgr.ins.remove(this.removeLoading, this);
        if (this._loading) {
            LayerManager.ins.loading.removeChild(this._loading);
            this._loading.dispose();
            this._loading = null;
        }
    }
    public showCoin(coin: number, parent, start: Vec2, end: Vec2, call?: Function): void {
        const render: fgui.GComponent = fgui.UIPackage.createObject(`Main`, `CoinRender`).asCom;
        render.getChild(`txt`).text = coin + "";
        render.touchable = false;
        render.setPosition(start.x, start.y);
        render.setScale(0, 0);
        parent.addChild(render);
        tween(render).to(0.2, { scaleX: 1, scaleY: 1 }).delay(0.3).to(0.4, { x: end.x, y: end.y }).call((data: fgui.GObject) => {
            data.removeFromParent();
            data.dispose();
            if (call) {
                call();
                call = null;
            }
        }).start();
    }
}